package algorithm.swordoff;

public class SQ58_1 {
    public String reverseWords(String s) {
        String[] split = s.trim().split("\\s+");
        StringBuilder sb = new StringBuilder();
        for (int i = split.length - 1; i >= 0; i--) {
            sb.append(split[i]).append(" ");
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        SQ58_1 sq58_1 = new SQ58_1();
        System.out.println(sq58_1.reverseWords("  a hel !word "));
    }
}
